Skip to content

Prepare shared code: Support running on non default dns settings #893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
Oct 17, 2024

Conversation

maltesander
Copy link
Member

@maltesander maltesander commented Oct 16, 2024

Description

Part of stackabletech/issues#436.

Definition of Done Checklist

  • Not all of these items are applicable to all PRs, the author should update this template to only leave the boxes in that are relevant
  • Please make sure all these things are done and tick the boxes
# Author
- [x] Changes are OpenShift compatible
- [ ] CRD changes approved
- [ ] Integration tests passed (for non trivial changes)
# Reviewer
- [x] Code contains useful comments
- [ ] (Integration-)Test cases added
- [ ] Documentation added or updated
- [x] Changelog updated
- [x] Cargo.toml only contains references to git tags (not specific commits or branches)
# Acceptance
- [ ] Feature Tracker has been updated
- [ ] Proper release label has been added

@Techassi Techassi self-requested a review October 16, 2024 12:37
@sbernauer sbernauer self-requested a review October 16, 2024 13:51
Copy link
Member

@Techassi Techassi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partial review.

Would you mind if I added a bunch of commits to this PR to adjust a few things?

@maltesander
Copy link
Member Author

Partial review.

Would you mind if I added a bunch of commits to this PR to adjust a few things?

Just pushed my test fix, did not look at your changes. Dont plan on pushing more today (do a little testing) so feel free to add :)

Techassi and others added 10 commits October 16, 2024 16:52
There is still some bits and pieces we want to change, mostly regarding
the error type / error handling.

This commit also moves the input fixtures for testing the resolv parser
into dedicated files and utilizies rstest's #[files] attribute to generate
tests based on these files.

Co-authored-by: Nick Larsen <nick.larsen@stackable.tech>
Co-authored-by: Techassi <git@techassi.dev>
@maltesander maltesander requested a review from Techassi October 17, 2024 08:56
sbernauer
sbernauer previously approved these changes Oct 17, 2024
Copy link
Member

@sbernauer sbernauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM otherwise

Co-authored-by: Sebastian Bernauer <sebastian.bernauer@stackable.de>
sbernauer
sbernauer previously approved these changes Oct 17, 2024
Copy link
Member

@sbernauer sbernauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks, looks good!

sbernauer
sbernauer previously approved these changes Oct 17, 2024
Copy link
Member

@NickLarsenNZ NickLarsenNZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some suggestions about error handling. I'm happy to make the changes if you want?

Co-authored-by: Malte Sander <malte.sander.it@gmail.com>
Co-authored-by: Techassi <sascha.lautenschlaeger@stackable.tech>
Co-authored-by: Malte Sander <malte.sander.it@gmail.com>
Co-authored-by: Techassi <sascha.lautenschlaeger@stackable.tech>
Copy link
Member

@NickLarsenNZ NickLarsenNZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@NickLarsenNZ NickLarsenNZ dismissed Techassi’s stale review October 17, 2024 13:49

Already dismissed

@maltesander maltesander added this pull request to the merge queue Oct 17, 2024
Merged via the queue into main with commit 5cf02b5 Oct 17, 2024
10 checks passed
@maltesander maltesander deleted the support-running-on-non-default-dns-settings branch October 17, 2024 15:48
Comment on lines +630 to +633
let _ = KUBERNETES_CLUSTER_DOMAIN
.set(retrieve_cluster_domain().context(ResolveKubernetesClusterDomainSnafu)?);
create_client(field_manager).await
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this a global?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its supposed to be the new "entry point" for operators. There will be more content in there in the future.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's basically renaming create_client to initialize_operator to be more expressive. By doing this we enforce that operators need to go throw this function and therefore initialize the OnceLock

Copy link
Member

@nightkr nightkr Oct 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's basically renaming create_client to initialize_operator to be more expressive.

But it.. isn't? It says less about what's happening, nor does it explain why this place would be the entry point.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There will be more content in there in the future.

Such as?

By doing this we enforce that operators need to go throw this function and therefore initialize the OnceLock

This still doesn't explain why it needs to be a OnceLock.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such as?

I have branch where I warn on an unsupported Kubernetes version. It's just not merged yet because of prioritization. In the future it may also read in the recommended product version or some global config object or whatnot or check if there is an update available.

This still doesn't explain why it needs to be a OnceLock.

Agreed, I didn't try do explain that. Do you have an alternative suggestion how we can make this easy-to-use in operators? It looks very intuitive to me, but I'm not a Rust expert!
In the beginning we had a LazyLock, but @Techassi mentioned that we would panic on e.g. an invalid DomainName being configured, and that the operators should error instead of panic, so we needed to change to a OnceLock.

Copy link
Member

@nightkr nightkr Oct 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have branch where I warn on an unsupported Kubernetes version.

That still sounds like a part of.. creating a k8s client.

Agreed, I didn't try do explain that. Do you have an alternative suggestion how we can make this easy-to-use in operators? It looks very intuitive to me, but I'm not a Rust expert!

I would have said you could store it in the Client, but on second thought maybe it would make more sense to create a separate KubernetesClusterConfig struct.

LazyLock/OnceLock is for caching expensive static values that can't be const for whatever reason (like a precomputed HashMap), not for configuration.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We replaced the LacyLock with a KubernetesClusterInfo struct in #896


match env::var(KUBERNETES_SERVICE_HOST_ENV) {
Ok(_) => {
let cluster_domain = retrieve_cluster_domain_from_resolv_conf(RESOLVE_CONF_FILE_PATH)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going to do this hack (and I still don't think we should), can we please at least punt that until vNext instead of sneaking it in just before the release?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have many customers that require this, i think there is no way to punt on this for now, but calls for intensive testing for sure!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can punt on autodetection while still keeping the override.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We removed auto-detection in #896 again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants